﻿namespace Guia.Elements
{
    using System.Windows.Automation;
    using Guia.Elements.PatternServants;
    using Guia.Locator;

    /// <summary>
    /// This class represents a RadioButton.
    /// </summary>
    public class RadioButton : UiElement, ISelectionItemSimple
    {
        /// <summary>
        /// Represents a helper-servant for the SelectionItem-pattern.
        /// </summary>
        private readonly ISelectionItemSimple selectionItemServant;

        /// <summary>
        /// Initializes a new instance of the RadioButton class. 
        /// </summary>
        /// <param name="automationElement">The AutomationElement representating the RadioButton.</param>
        public RadioButton(AutomationElement automationElement)
            : base(automationElement)
        {
            this.selectionItemServant = new SelectionItemImpl(this);
        }

        /// <summary>
        /// Gets the default-condition to find a control by its type.
        /// </summary>
        public static SearchCondition ControlTypeCondition
        {
            get { return SearchCondition.ByControlType(ControlType.RadioButton); }
        }

        /// <summary>
        /// Gets a value indicating whether this RadioButton is selected or not.
        /// </summary>
        public bool IsSelected
        {
            get { return this.selectionItemServant.IsSelected; }
        }

        /// <summary>
        /// Select this radio-button.
        /// </summary>
        public void Select()
        {
            this.selectionItemServant.Select();
        }
    }
}
